home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 272_01 / okiset.c < prev    next >
Text File  |  1987-03-28  |  11KB  |  413 lines

  1. /*
  2. **                OKIDATA PRINTER SETUP UTILITY
  3. ** Copyright 1987, S.E. Margison
  4. ** 1-11-87 A
  5. **
  6. **   As distributed, this program requires (for compilation):
  7. **     "Steve's Datalight Library" version 1.10 or later
  8. **   which may be obtained without registration from many Bulletin
  9. **   Board Systems including:
  10. **      Compuserve IBMSW
  11. **      Cul-De-Sac (Holliston, MA.)
  12. **      HAL-PC BBS (Houston, TX.)
  13. **   and software library houses including:
  14. **      Public (Software) Library (Houston, TX.)
  15. **
  16. **   or by registration:
  17. **      $10 for Docs, Small Model Library
  18. **      $25 for Docs, S, D, L, P libraries, and complete library source
  19. **              in C and Assembler
  20. **     Steven E. Margison
  21. **     124 Sixth Street
  22. **     Downers Grove, IL, 60515
  23. **
  24. */
  25.  
  26. #include <stdio.h>
  27. #include <smdefs.h>
  28. #include <keys.h>
  29.  
  30. #define NONE 0xff
  31. #define PICA 0
  32. #define COND 1
  33. #define DRAFT 0
  34. #define LQ 1
  35. #define beep putchar(BELL)
  36.  
  37. short length, linespc, lqspc, pitch, style;
  38. short printer;  /* 0 = PRN, 1 = LPT1, 2 = LPT2 */
  39.  
  40. char pica[] =  "NORMAL   ",
  41.      cond[] =  "CONDENSED",
  42.      draft[] = "DRAFT         ",
  43.      lq[] =    "LETTER QUALITY",
  44.      lpt1[] = "LPT1:",
  45.      lpt2[] = "LPT2:",
  46.      prn[] = "PRN: ";
  47.  
  48. char line1[] = "OKIDATA ML84 CONFIGURATOR V1.10",
  49.      line2[] = "- by Steven E. Margison -",
  50.      line3[] = "Copyright 1986 -- All Rights Reserved",
  51.      line4[] = "F1   Pitch: ",
  52.      line5[] = "F2   Style: ",
  53.      line6[] = "F3   LQ spacing: ",
  54.      line7[] = "F4   Form Length (lines): ",
  55.      line8[] = "F5   Line Spacing: ",
  56.      line9[] = "F6   ",
  57.      line10[]= "F7   Output Channel - ",
  58.      line11[]= "F8   Normal Defaults",
  59.      line12[]= "F9   Send Control Codes",
  60.      line13[]= "FK10  -- Return to DOS --",
  61.      line14[]= "Waiting...",
  62.      cline[]="                                                        ";
  63.  
  64. main() {           /* no command line arguments */
  65.    int key;
  66.    printer = 0;
  67.    lqspc = linespc = pitch = style = length = NONE;
  68.    domenu(NO);           /* initialize the screen */
  69.  
  70.    while(YES) {
  71.       key = getkey();    /* get a function code */
  72.       if(key < 0xff) {
  73.          beep;
  74.          continue;
  75.          }
  76.       key &= 0x7f;
  77.       switch(key) {
  78.          case FK1:   /* select pitch */
  79.             dofk1();
  80.             if((pitch is COND) and (style is LQ)) {
  81.                style = DRAFT;
  82.                putstyle();
  83.                }
  84.             prompt();
  85.             break;
  86.          case FK2:   /* select style */
  87.             dofk2();
  88.             if((style is LQ) and (pitch is COND)) {
  89.                pitch = PICA;
  90.                putpitch();
  91.                }
  92.             prompt();
  93.             break;
  94.          case FK3:   /* specify LQ character spacing */
  95.             if((lqspc = get2digs(9, 32)) is NONE) { prompt(); break; }
  96.             if(style isnot LQ) {
  97.                style = LQ;
  98.                putstyle();
  99.                if(pitch is COND) {
  100.                   pitch = PICA;
  101.                   putpitch();
  102.                   }
  103.                }
  104.             if(lqspc > 0x11) {
  105.                lqspc = 0;
  106.                warn(1);
  107.                putlqspc();
  108.                }
  109.             prompt();
  110.             break;
  111.          case FK4:   /* specify Form length in lines */
  112.             if((length = get2digs(10, 41)) is NONE) { prompt(); break; }
  113.             if(length is 0) {
  114.                length = 0x66;
  115.                warn(2);
  116.                putlength();
  117.                }
  118.             prompt();
  119.             break;
  120.          case FK5:  /* specify line spacing */
  121.             dofk5();
  122.             prompt();
  123.             break;
  124.          case FK6:
  125.             beep;
  126.             break;
  127.          case FK7:  /* select output channel */
  128.             dokey7();
  129.             prompt();
  130.             break;
  131.          case FK8:   /* set normal options */
  132.             linespc = 0;  /* 6 lpi */
  133.             putlinespc();
  134.             length = 0x66;
  135.             putlength();
  136.             style = DRAFT;
  137.             putstyle();
  138.             pitch = PICA;
  139.             putpitch();
  140.             lqspc = NONE;
  141.             putlqspc();
  142.             printer = 0;
  143.             putprinter();
  144.             prompt();
  145.             break;
  146.          case FK9:  /* write the codes out and exit */
  147.             dofk9();
  148.             break;
  149.          case FK10:
  150.             exit2dos();
  151.             domenu(YES);
  152.             break;
  153.          default:
  154.             beep;
  155.          }   /* end of switch */
  156.       }      /* end of main while */
  157.    }         /* end of main() */
  158.  
  159.  
  160. domenu(cmd) int cmd; {
  161.    int i;
  162.    /* if cmd is YES, then place current setting in menu for each item */
  163.    cls();
  164.    mkbox(0, 0, 80, 22, 0);   /* place the border on blank screen */
  165.    i = cntr(line1);
  166.    d_say(3, i, line1);
  167.    i = cntr(line2);
  168.    d_say(4, i, line2);
  169.    i = cntr(line3);
  170.    d_say(5, i, line3);
  171.    d_say(7, 15, line4);
  172.    if(cmd and (pitch isnot NONE)) putpitch();
  173.    d_say(8, 15, line5);
  174.    if(cmd and (style isnot NONE)) putstyle();
  175.    d_say(9, 15, line6);
  176.    if(cmd and (lqspc isnot NONE)) putlqspc();
  177.    d_say(10, 15, line7);
  178.    if(cmd and (length isnot NONE)) putlength();
  179.    d_say(11, 15, line8);
  180.    if(cmd and (linespc isnot NONE)) putlinespc();
  181.    d_say(12, 15, line9);
  182.    d_say(13, 15, line10);
  183.    putprinter();
  184.    d_say(14, 15, line11);
  185.    d_say(15, 15, line12);
  186.    d_say(16, 15, line13);
  187.    prompt();
  188.    }
  189.  
  190. cntr(str) char *str; {   /* returns column to start printing */
  191.    int i;
  192.    i = strlen(str);
  193.    --i;     /* account for newline character */
  194.    return(((80 - i) / 2) - 1);
  195.    }
  196.  
  197. prompt() {
  198.    d_say(19, 15, cline);
  199.    d_say(19, 15, line14);
  200.    }
  201.  
  202. warn(value) int value; {
  203.    beep;
  204.    switch(value) {
  205.       case 1:
  206.          d_say(19, 15, "Value too large.  Range is 0-11.");
  207.          break;
  208.       case 2:
  209.          d_say(19, 15, "Length value of 0 meaningless.");
  210.          break;
  211.       default:
  212.          prompt();
  213.          return;
  214.       }
  215.    d_say(20, 15, "Strike any key to continue...");
  216.    getkey();
  217.    d_say(20, 15, cline);
  218.    prompt();
  219.    }
  220.  
  221.  
  222. putpitch() {
  223.    if(pitch is PICA) { d_say(7, 27, pica); return; }
  224.    if(pitch is COND) { d_say(7, 27, cond); return; }
  225.    }
  226.  
  227. putstyle() {
  228.    if(style is DRAFT) { d_say(8, 27, draft); return; }
  229.    if(style is LQ) { d_say(8, 27, lq); return; }
  230.    }
  231.  
  232. putlqspc() {
  233.    char i;
  234.    d_pos(9, 32, 0);
  235.    if(lqspc is NONE) { fputs("  ", stdout); return; }
  236.    i = (char)((lqspc >>4) | '0');
  237.    fputc(i, stdout);
  238.    i = (char)((lqspc & 0x0f) | '0');
  239.    fputc(i, stdout);
  240.    }
  241.  
  242. putlength() {
  243.    char i;
  244.    d_pos(10, 41, 0);
  245.    i = (char)((length >>4) | '0');
  246.    fputc(i, stdout);
  247.    i = (char)((length & 0x0f) | '0');
  248.    fputc(i, stdout);
  249.    }
  250.  
  251. putlinespc() {
  252.    d_pos(11, 34, 0);
  253.    if(linespc is 0) puts("6 lpi");
  254.    else puts("8 lpi");
  255.    }
  256.  
  257. putprinter() {
  258.    d_pos(13, 37, 0);
  259.    switch(printer) {
  260.       case 0: default:
  261.          puts(prn);
  262.          return;
  263.       case 1:
  264.          puts(lpt1);
  265.          return;
  266.       case 2:
  267.          puts(lpt2);
  268.          return;
  269.       }
  270.    }
  271.  
  272. dofk1() {
  273.    char chr;
  274.    if(pitch is NONE) { pitch = PICA; putpitch(); }
  275.    d_pos(7, 27, 0);
  276.    while((chr = getkey()) isnot '\r') {
  277.       if(chr > 255) { beep; continue; }
  278.       if(chr isnot ' ') { beep; continue; }
  279.       ++pitch;
  280.       pitch &= 0x01;  /* toggle between 0 and 1 only */
  281.       putpitch();
  282.       d_pos(7, 27, 0);
  283.       }
  284.    }
  285.  
  286. dofk2() {
  287.    char chr;
  288.    if(style is NONE) { style = DRAFT; putstyle(); }
  289.    d_pos(8, 27, 0);
  290.    while((chr = getkey()) isnot '\r') {
  291.       if(chr > 255) { beep; continue; }
  292.       if(chr isnot ' ') { beep; continue; }
  293.       ++style;
  294.       style &= 0x01;  /* toggle between 0 and 1 only */
  295.       putstyle();
  296.       d_pos(8, 27, 0);
  297.       }
  298.    }
  299.  
  300. dofk5() {
  301.    char chr;
  302.    if(linespc is NONE) { linespc = 0; putlinespc(); }
  303.    d_pos(11, 34, 0);
  304.    while((chr = getkey()) isnot '\r') {
  305.       if(chr > 255) { beep; continue; }
  306.       if(chr isnot ' ') { beep; continue; }
  307.       ++linespc;
  308.       linespc &= 0x01;  /* toggle